Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports C4F.DevKit.Contacts.Data

Namespace C4F.DevKit.Contacts.Samples.Win
	Public Partial Class ContactDBList
		Inherits Form
		#Region "Private Data"

		Private _simpleContacts As SimpleContactDataSet = Nothing

		#End Region ' Private Data

		#Region "Constants"

		Private Const CONTACTID_COLUMN_INDEX As Integer = 0
		Private Const FIRSTNAME_COLUMN_INDEX As Integer = 1
		Private Const MIDDLENAME_COLUMN_INDEX As Integer = 2
		Private Const LASTNAME_COLUMN_INDEX As Integer = 3

		Private Const CONTACTID_COLUMN_SOURCE As String = "ContactID"
		Private Const FIRSTNAME_COLUMN_SOURCE As String = "FirstName"
		Private Const MIDDLE_COLUMN_SOURCE As String = "MiddleName"
		Private Const LASTNAME_COLUMN_SOURCE As String = "LastName"

		#End Region ' Constants

		#Region "Properties"

		Public ReadOnly Property ContactID() As Guid
			Get
				If dgContactList.SelectedRows.Count < 1 Then
					Return Guid.Empty
				Else
					Return New Guid(dgContactList.SelectedRows(0).Cells(CONTACTID_COLUMN_INDEX).Value.ToString())
				End If
			End Get
		End Property

		#End Region ' Properties

		#Region "Constructors"

		Public Sub New()
			InitializeComponent()

			Try
				_simpleContacts = contactsService1.GetSimpleContactsFromDatabase()
			Catch ex As Exception
				DisplayException(ex)
			End Try
		End Sub

		#End Region ' Constructors

		#Region "Methods"

		#Region "EventHandlers"

		Private Sub ContactDBList_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
			InitializeBinding()
		End Sub

		#End Region ' EventHandlers

		#Region "Private "

		Private Sub DisplayException(ByVal ex As Exception)
			If Not ex Is Nothing Then
				MessageBox.Show(ex.ToString())
			End If
		End Sub

		Private Sub InitializeBinding()
			If Not _simpleContacts Is Nothing Then
				bindingSource1.DataSource = _simpleContacts
				bindingSource1.DataMember = "SimpleContact"

				dgContactList.Columns(CONTACTID_COLUMN_INDEX).DataPropertyName = CONTACTID_COLUMN_SOURCE
				dgContactList.Columns(FIRSTNAME_COLUMN_INDEX).DataPropertyName = FIRSTNAME_COLUMN_SOURCE
				dgContactList.Columns(MIDDLENAME_COLUMN_INDEX).DataPropertyName = MIDDLE_COLUMN_SOURCE
				dgContactList.Columns(LASTNAME_COLUMN_INDEX).DataPropertyName = LASTNAME_COLUMN_SOURCE
			End If
		End Sub

		#End Region ' Private

		#End Region ' Methods
	End Class
End Namespace
